# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=micropython
pkgver=1.12
pkgrel=1
pkgdesc="A lean and efficient Python implementation for MCUs and constrained systems"
url="https://www.micropython.org/"

# ppc64le: mpy-cross fails to compile with "unsupported relocation
# armv7: 21 unit tests fail (not minor stuff line double precision issues)
# armhf: fails to build
arch="all !ppc64le !armv7 !armhf"

license="MIT"
makedepends="libffi-dev python3"
subpackages="$pkgname-cross"
source="micropython-$pkgver.tar.gz::https://github.com/micropython/micropython/archive/v$pkgver.tar.gz
	micropython-1.9.4-prevent-stripping.patch
	python3.patch
	no_ussl.patch
	no_legacy_berkeley_db.patch
	"

build() {
	make -C mpy-cross PYTHON=python3
	make -C ports/unix PYTHON=python3
}

check() {
	# float rounding fails https://github.com/micropython/micropython/issues/4176
	case "$CARCH" in
		s390x)
			rm tests/float/float_parse.py tests/float/float_parse_doubleprec.py
			;;
		aarch64)
			rm tests/float/float_parse.py tests/float/float_parse_doubleprec.py
			;;
	esac

	# ffi callback fails on kernel with PaX
	rm tests/unix/ffi_callback.py

	make -C ports/unix test PYTHON=python3
}

package() {
	mkdir -p "$pkgdir/usr/bin"
	install -m755 ports/unix/micropython "$pkgdir/usr/bin/micropython"
}

cross() {
	pkgdesc="Compile micropython code to bytecode, which can be transfered to MCUs"
	cd "$builddir"
	mkdir -p "$subpkgdir/usr/bin"
	install -m755 mpy-cross/mpy-cross "$subpkgdir/usr/bin/mpy-cross"
}

sha512sums="624688bdf658f63de2257eed7b903a2a1bebaf02436feed09e0893090f49052d0e1b3d55ee8128f5ea813586f5c1e3d6cce6a8230be7fdb418509bb3b734b5ca  micropython-1.12.tar.gz
8f994394f42d7fed5fa35b62c01c37ebea3b487c029d659134a263ef8d65e1ec17bec755fdf57cde2f234969bc4f7f4ab30858562d7f8cdb2bc6cb819ba2ae0d  micropython-1.9.4-prevent-stripping.patch
8dbdc52e09f70b5eea461257ebc00031ab9d2c91a9bdbd7522e4ffd1eddddcd0dab3a171361e776543abca827a2f5d6ad01b06c10c8635db861bf79bfa065338  python3.patch
9a6cd131c8875a9d320653b7b93d46a759eee3255e25763eb8de6934b3035f691e497eafc9412320f13c5921a384d42d6e60ea3eb3d65f3a6101dae9be514f3c  no_ussl.patch
e86ad02ef746605f2f685ae776a6ad6ea39ae6e57fa0869a0c03895fd581647de20fa7e6aaeebac45e7302a63451d625208b1356ee2f35a66df70ac2755a25ff  no_legacy_berkeley_db.patch"
